import 'package:get/get.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/application/get_distribute_return_record_list_entity.dart';
import 'package:safetymonitor/app/data/entities/home/warning/alarm_resp_entity.dart';

import '../controller.dart';
///已完成的详情
class CompletedDetailController extends GetxController {
  /// 列表控制器
  final listController = Get.find<CompletedController>();
  ///退回信息和验收信息记录
  GetDistributeReturnRecordListEntity getDistributeReturnRecordListEntity = GetDistributeReturnRecordListEntity();
  /// 实体数据
  AlarmRespEntity entity = Get.arguments as AlarmRespEntity;

  @override
  void onInit() {
    super.onInit();
    //退回记录，验收记录的查询
    getDistributeReturnList();
    getDetailsData();
  }

  ///获得企业基本信息
  void getDistributeReturnList() async {
    final res = await HttpUtil().generateGetRequest<GetDistributeReturnRecordListEntity>(
      Interface.getDistributeReturnRecordList,
      queryParameters: {'alarmId': entity.id},
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        getDistributeReturnRecordListEntity = result.data!;
      }
      update();
    });
  }

  /// 获取详情数据
  void getDetailsData() async {
    final res = await HttpUtil().generateGetRequest<AlarmRespEntity>(
      Interface.getAlarmDetailPage,
      queryParameters: {'id': entity.id},
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        entity = result.data!;
      }
      update();
    });
  }
}

